const config=require('../config');
const {Book,Total}=require('../models/index');
const cats=require('./cats.json');
const getCatTotalPaging=require('./getCatTotalPaging');
const saveCatTotalPaging=require('./saveCatTotalPaging');

class Spider {
    constructor(){
        this.init();
        this.totals;
    }

    async init(){
        await this.initTotalDB();
    }

    async initTotalDB(){
        let tasks=[];
        for(let cat of cats){
            tasks.push(getCatTotalPaging(cat));
        }
        this.totals=await Promise.all(tasks);
        this.totals=this.totals.filter(t=>t);
        await saveCatTotalPaging(this.totals);
        console.log('saveCatTotalPaging!!');
    }

}

new Spider();